<?php
/**
 * Created by PhpStorm.
 * User: wutian
 * Date: 2015/1/9
 * Time: 19:37
 */

namespace Home\Controller;


class ApiController extends \Think\Controller {

    protected $msg = "success";
    protected $code = 200;
    protected $data = array();

   function __construct()
   {
       parent::__construct();
   }

    function json($data,$code="200",$msg="success")
    {
        $this->code = $code;
        $this->msg = $msg;
        $this->data = $data;
    }

    function getJson()
    {
        return array('code'=>$this->code,'msg'=>$this->msg,'data'=>$this->data);
    }

    function __destruct(){
        global $json;
        $json = array('c'=>$this->code,'m'=>$this->msg,'d'=>$this->data);
        if(APP_DEBUG){
            $this->ajaxReturn($this->getJson());
        }
        parent::__destruct();
    }

} 